package com.ty.enums;

import lombok.Getter;
import lombok.Setter;

import java.util.Arrays;
import java.util.Optional;

public enum ShelfStatus {
    NORMAL(1,"正常"),
    OFF_SHELF(2,"弃用");


    @Getter @Setter
    private int code;
    @Getter @Setter
    private String message;

    ShelfStatus(int code, String messgae) {
        this.code =code;
        this.message =messgae;
    }

    public static ShelfStatus getByCode(int code){
        ShelfStatus[] values = ShelfStatus.values();
        //jdk1.8 “新”特性 stream流
        //jdk1.8 “新”特性 Optional
        Optional<ShelfStatus> first = Arrays.stream(values).filter(item -> item.getCode() == code).findFirst();
//        if( first.isPresent()){ //如果这个Optional容器里面有值，就返回 get() 返回容器里面的值
//            return first.get();
//        }
//        return null;
        return first.orElse(null);
    }
}
